﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing; // For Point
using System.Windows.Forms; // For RichTextBox

namespace RobotCleaner
{
    /// <summary>
    /// 清扫分析类
    /// </summary>
    public class CleanAnalyze // Sep 26,2013 15:07 EndlessRain
    {
        /// <summary>
        /// 机器人参数节点链表
        /// </summary>
        List<RobotParaNode> R_Node = new List<RobotParaNode>();
        /// <summary>
        /// 机器人参数 最后角度
        /// </summary>
        public int LastDegree
        {
            get { return R_Node[R_Node.Count - 1].Degree; }
        }
        /// <summary>
        /// 机器人参数 最后路程
        /// </summary>
        public int LastS
        {
            get { return R_Node[R_Node.Count - 1].S;}
        }
        /// <summary>
        /// 机器人参数 最后一个节点 
        /// </summary>
        /// <returns></returns>
        public Point LastPoint
        {
            get { return new Point(R_Node[R_Node.Count - 1].X, R_Node[R_Node.Count - 1].Y); }
        }
        /// <summary>
        /// 返回机器人参数节点个数
        /// </summary>
        public int NodeCount
        {
            get { return R_Node.Count; }
        }
        /// <summary>
        /// 增加节点
        /// </summary>
        /// <param name="_degree">角度</param>
        /// <param name="_s">路程</param>
        /// <param name="_x">X分量</param>
        /// <param name="_y">Y分量</param>
        public void AddNode(int _degree,int _s,int _x,int _y)
        {
            R_Node.Add(new RobotParaNode(_degree,_s,_x,_y));
        }
        /// <summary>
        /// 删除最后一个节点
        /// </summary>
        public void DeleteLastNode()
        {
            R_Node.RemoveAt(R_Node.Count - 1);
        }
        /// <summary>
        /// 清空所有节点
        /// </summary>
        public void ClearNode()
        {
            R_Node.Clear();
        }
        //private int count = 0;
        /// <summary>
        /// 根据参数 返回机器人的行进角度
        /// </summary>
        /// <returns></returns>
        public float Analyze(int L,int R,int[] T)
        {
            float angle = 0.0f;
            if (L == 0 && R == 0)
            {
                angle = 90.0f;
            }
            if (L == 0 && R == 1)
            {

            }
            if (L == 1 && R == 0)
            {
                
            }
            if (L == 1 && R == 1)
            {
                angle = 30.0f;
            }
            return angle;
        }
        /// <summary>
        /// 输出信息
        /// </summary>
        public void Output(RichTextBox r)
        {
            for (int i = R_Node.Count-1; i < R_Node.Count; i++)
            {
                string s = String.Format("Degree:{0} S:{1} X:{2} Y:{3}\n",
                     R_Node[i].Degree,R_Node[i].S,R_Node[i].X,R_Node[i].Y);
                r.Text += s;
            }
            r.Text += "============\n";
        }
        /// <summary>
        /// 机器人参数节点
        /// </summary>
        private class RobotParaNode
        {
            private int _degree;
            private int _s;
            private int _x;
            private int _y;
            /// <summary>
            /// 角度
            /// </summary>
            public int Degree
            {
                get { return _degree;}
                set { _degree = value; }
            }
            /// <summary>
            /// 里程
            /// </summary>
            public int S
            {
                get { return _s; }
                set { _s = value; }
            }
            /// <summary>
            /// 相对出发点的X值
            /// </summary>
            public int X
            {
                get { return _x; }
                set { _x = value; }
            }
            /// <summary>
            /// 相对出发点的Y值
            /// </summary>
            public int Y
            {
                get { return _y; }
                set { _y = value; }
            }
            /// <summary>
            /// 机器人节点 构造函数初始化
            /// </summary>
            /// <param name="_degree"></param>
            /// <param name="_s"></param>
            /// <param name="_x"></param>
            /// <param name="_y"></param>
            public RobotParaNode(int degree,int s, int x,int y)
            {
                _degree = degree;
                _s = s;
                _x = x;
                _y = y;
            }
        }
    }
}
